package com.admin.business.portalWebsite.venusArticleSet;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 文章设置关联表
 * @create: 2023-11-18 14:42:27
 **/
@Service("venusArticleSetService")
@Slf4j
public class VenusArticleSetService{

    @Resource
    VenusArticleSetDao venusArticleSetDao;

    /**
     * 添加文章设置关联表,获取id数据
     *
     * @param cdoRequest - id:
     *                   - article_id:资讯id
     *                   - set_id:设置id
     *                   - org_id:
     * @return
     * @author wdf
     * @create: 2023-11-18 14:42:27
     */
    @OpenApi
    public Return addVenusArticleSet(CDO cdoRequest) {
        venusArticleSetDao.addVenusArticleSet(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新文章设置关联表数据
     *
     * @param cdoRequest - id:
     *                   - article_id:资讯id
     *                   - set_id:设置id
     *                   - org_id:公司id
     * @return
     * @author wdf
     * @create: 2023-11-18 14:42:27
     */
    @OpenApi
    public Return updateVenusArticleSetById(CDO cdoRequest) {
        venusArticleSetDao.updateVenusArticleSetById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除文章设置关联表数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-11-18 14:42:27
     */
    @OpenApi
    public Return deleteVenusArticleSetById(CDO cdoRequest){
        int count = venusArticleSetDao.deleteVenusArticleSetById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除文章设置关联表数据
     *
     * @param cdoRequest - article_id:资讯id
     *                   - set_id:设置id
     *                   - org_id:公司id
     * @return
     * @author wdf
     * @create: 2023-11-18 14:42:27
     */
    @OpenApi
    public Return deleteVenusArticleSet(CDO cdoRequest) {
        int count = venusArticleSetDao.deleteVenusArticleSet(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取文章设置关联表数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-11-18 14:42:27
     */
    @OpenApi
    public Return getVenusArticleSetById(CDO cdoRequest) {
        CDO cdoMapperResult = venusArticleSetDao.getVenusArticleSetById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取文章设置关联表数据列表
     *
     * @param cdoRequest - article_id:资讯id
     *                   - set_id:设置id
     *                   - org_id:公司id
     * @return
     * @author wdf
     * @create: 2023-11-18 14:42:27
     */
    @OpenApi
    public Return getVenusArticleSetListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusArticleSetDao.getVenusArticleSetListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusArticleSetDao.getVenusArticleSetCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取文章设置关联表数据列表
     *
     * @param cdoRequest - id:
     *                   - article_id:资讯id
     *                   - set_id:设置id
     *                   - org_id:公司id
     * @return
     * @author wdf
     * @create: 2023-11-18 14:42:27
     */
    @OpenApi
    public Return getVenusArticleSetListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusArticleSetDao.getVenusArticleSetListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusArticleSetDao.getVenusArticleSetCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
